package graphics;

/**
 * Shape Factory is a factory class which is used to create a shape by either
 * their name or their class
 * 
 * @author Jie Zhao(288654)
 * 
 */
public class ShapeFactory {

	private ShapeFactory() {
	}

	/**
	 * create a shape by name
	 * 
	 * @param name
	 * @return an object of the shape specified by name
	 */
	public static Shape createShapeByName(String name) {
		if (name == null || "".equals(name)) {
			return null;
		}
		if (name.equalsIgnoreCase("Line")) {
			return new Line();
		} else if (name.equalsIgnoreCase("Oval")) {
			return new Oval();
		} else if (name.equalsIgnoreCase("Rectangle")) {
			return new Rectangle();
		} else if (name.equalsIgnoreCase("Triangle")) {
			return new Triangle();
		} else if (name.equalsIgnoreCase("Circle")) {
			return new Circle();
		} else if (name.equalsIgnoreCase("Star")) {
			return new Star();
		} else if (name.equalsIgnoreCase("Text")) {
			return new Text();
		} else if (name.equalsIgnoreCase("FreePen")) {
			return new FreePen();
		} else if (name.equalsIgnoreCase("Eraser")) {
			return new Eraser();
		} else if (name.equalsIgnoreCase("Polygon")) {
			return new Polygon();
		} else {
			return null;
		}
	}

	public static Shape createShapeByString(String str)
	{
		if (str == null || "".equals(str)) {
			return null;
		}
		if (str.startsWith("line")) {
			return new Line();
		} else if (str.startsWith("oval")) {
			return new Oval();
		} else if (str.startsWith("rectangle")) {
			return new Rectangle();
		} else if (str.startsWith("triangle")) {
			return new Triangle();
		} else if (str.startsWith("circle")) {
			return new Circle();
		} else if (str.startsWith("star")) {
			return new Star();
		} else if (str.startsWith("text")) {
			return new Text();
		} else if (str.startsWith("freepen")) {
			return new FreePen();
		} else if (str.startsWith("eraser")) {
			return new Eraser();
		} else if (str.startsWith("polygon")) {
			return new Polygon();
		} else {
			return null;
		}
	}
	
	/**
	 * Create a shape of a specified shape class
	 * 
	 * @param shapeClass
	 * @return an object of the specified class
	 */
	public static Shape createShapeByClass(Class shapeClass) {
		if (shapeClass == null) {
			return null;
		}
		if (shapeClass.equals(Line.class)) {
			return new Line();
		} else if (shapeClass.equals(Oval.class)) {
			return new Oval();
		} else if (shapeClass.equals(Rectangle.class)) {
			return new Rectangle();
		} else if (shapeClass.equals(Triangle.class)) {
			return new Triangle();
		} else if (shapeClass.equals(Circle.class)) {
			return new Circle();
		} else if (shapeClass.equals(Star.class)) {
			return new Star();
		} else if (shapeClass.equals(Text.class)) {
			return new Text();
		} else if (shapeClass.equals(FreePen.class)) {
			return new FreePen();
		} else if (shapeClass.equals(Eraser.class)) {
			return new Eraser();
		} else if (shapeClass.equals(Polygon.class)) {
			return new Polygon();
		} else {
			return null;
		}
	}
}
